/*Version 1.0*/
#include "Barre_outils_dessins.h"
#include "Boite_Saisie_Outils.h"

/*Creation de la barre d'outils*/
void CreationBarreOutilsDessins(Carre *c, Rectangle *rec, Cercle *cer, Plume *p)
{
  GtkWidget * pToolbar = NULL;
  /*Declaration des objets qui vont contenir les boutons*/
  GtkToolItem * Carr = NULL;
  GtkToolItem * Rectangle = NULL;
  GtkToolItem * Cercle = NULL;
  GtkToolItem * Plume = NULL;

  /*Declaration de la fenetre et de la "boite" qui va contenir la barre d'outils*/
  GtkWidget *pWindow;
  GtkWidget *pVBox;
  
  GtkWidget *button = gtk_button_new_with_label ("Carre");
  GtkWidget *button2 = gtk_button_new_with_label ("Rectangle");
  GtkWidget *button3 = gtk_button_new_with_label ("Cercle");
  GtkWidget *button4 = gtk_button_new_with_label ("Plume");

  
  InitCarre(c);
  InitRectangle(rec);
  InitCercle(cer);
  InitPlume(p);
	
  /*Creation de la fenetre */
  pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(pWindow), "Barre outils dessins");
  gtk_window_set_default_size(GTK_WINDOW(pWindow), 320,40);

  pVBox = gtk_box_new(TRUE,0);
  gtk_container_add(GTK_CONTAINER(pWindow), pVBox);
  
  /* Creation de la barre d'outils */
  pToolbar = gtk_toolbar_new();
  gtk_box_pack_start(GTK_BOX(pVBox), pToolbar, FALSE, FALSE, 0);
  
  gtk_widget_show (button);
  gtk_widget_show (button2);
  gtk_widget_show (button3);
  gtk_widget_show (button4);

  Carr = gtk_tool_button_new(button,NULL);
  Rectangle = gtk_tool_button_new(button2,NULL);
  Cercle = gtk_tool_button_new(button3,NULL);
  Plume = gtk_tool_button_new(button4,NULL);

  /*Insertion des boutons dans la barre d'outils */
  gtk_toolbar_insert(GTK_TOOLBAR(pToolbar),Carr,0);
  gtk_toolbar_insert(GTK_TOOLBAR(pToolbar),Rectangle,-1);
  gtk_toolbar_insert(GTK_TOOLBAR(pToolbar),Cercle,-1);
  gtk_toolbar_insert(GTK_TOOLBAR(pToolbar),Plume,-1);

  gtk_widget_show_all(pWindow);

  /*Appels des fonctions qui appelent les boites de saisies*/
  g_signal_connect (Carr,"clicked",G_CALLBACK (on_boutton_dessiner_carre),(gpointer)c);
  g_signal_connect (Rectangle,"clicked",G_CALLBACK (on_boutton_dessiner_rectangle),(gpointer)rec);
  g_signal_connect (Cercle,"clicked",G_CALLBACK (on_boutton_dessiner_cercle),(gpointer)cer);
  g_signal_connect (Plume,"clicked",G_CALLBACK (on_boutton_dessiner_plume),(gpointer)p);
}

/*Fonctions qui appelent les boites pour saisir les parametres des structures outils*/
gboolean on_boutton_dessiner_carre(GtkButton *button, gpointer user_data)
{
  Carre * c=(Carre*)user_data;
  boite_saisie_carre(c);
  return TRUE;
}

gboolean on_boutton_dessiner_rectangle(GtkButton *button, gpointer user_data)
{
  Rectangle * r=(Rectangle*)user_data;
  boite_saisie_rectangle(r);
  return TRUE;
}

gboolean on_boutton_dessiner_cercle(GtkButton *button, gpointer user_data)
{
  Cercle * cer=(Cercle*)user_data;
  boite_saisie_cercle(cer);
  return TRUE;
}

gboolean on_boutton_dessiner_plume(GtkButton *button, gpointer user_data)
{
  Plume * p=(Plume*)user_data;
  boite_saisie_plume(p);
  return TRUE;
}
